package com.guchenbo.example.httpclient;

import org.apache.commons.codec.binary.Base64;

import java.nio.charset.Charset;

/**
 * 封装了apache base64的异常
 *
 * @Author gucb
 * @Date 2017/6/16.
 */
public class Base64Utils {
    public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8");

    public static String decodeString(String content) {
        if (content != null) {
            content = new String(Base64.decodeBase64(content.getBytes(DEFAULT_CHARSET)), DEFAULT_CHARSET);
        }
        return content;
    }

    public static String encodeString(String content) {
        return Base64.encodeBase64String(content.getBytes(DEFAULT_CHARSET));
    }
}
